﻿using System;
using log4net;

namespace Eff.Utils
{
    /// <summary>
    /// 具有无参构造函数类型的单例容器
    /// </summary>
    public static class Singleton<T> where T : class, new()
    {
        private static readonly T instance;
        private static readonly ILog log = LogManager.GetLogger(typeof(Singleton<T>));

        static Singleton()
        {
            try
            {
                instance = new T();
            }
            catch (Exception e)
            {
                log.Error(e);
            }
        }

        /// <summary>
        /// 返回相同实例
        /// </summary>
        public static T Instance
        {
            get { return instance; }
        }
    }
}